package top.lixunda.books3.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.lixunda.books3.model.Message;
import top.lixunda.books3.model.SimpleGoods;
import top.lixunda.books3.service.GoodsService;

import java.util.List;

@Controller
@RequestMapping(value = "/goods")
public class GoodsController {

    private final GoodsService goodsService;

    @Autowired
    public GoodsController(GoodsService goodsService) {
        this.goodsService = goodsService;
    }

    @RequestMapping("/query")
    @ResponseBody
    public Message querySimpleGoodsByBook(long id, long start, int count){
        List<SimpleGoods> list = goodsService.querySimpleGoodsByBook(id, start, count);
        long total = goodsService.querySimpleGoodsCountByBook(id);
        return Message.successData(list).setFirst(start).setCount(list.size()).setTotal(total);
    }

}
